package com.zkingsoft.zkingbase.wxapi;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.zkingsoft.zkingbase.base.BaseActivity;
import com.zkingsoft.zkingbase.constant.Constant;

/***
 * 该activity为微信支付回调的activity必须名字为 WXPayEntryActivity 放到应用的包名的wxapi下
 */
public class WXPayEntryActivity extends BaseActivity implements IWXAPIEventHandler
{

    private static final String TAG = "MicroMsg.WXPayEntryActivity";

    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        api = WXAPIFactory.createWXAPI(this, Constant.WX_ID);
        api.handleIntent(getIntent(), this);
    }

    @Override
    public int getContentView()
    {
        return 0;
    }

    @Override
    protected void onNewIntent(Intent intent)
    {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req)
    {

    }

    @Override
    public void onResp(BaseResp resp)
    {
        if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX)
        {
            if (String.valueOf(resp.errCode).equals("0"))
            {
                // 支付成功
            } else if (String.valueOf(resp.errCode).equals("-1"))
            {
                // 支付错误
                WXPayEntryActivity.this.finish();
            } else if (String.valueOf(resp.errCode).equals("-2"))
            {
                // 用户取消
                WXPayEntryActivity.this.finish();
            }
        }
    }
}